/*
 * @Description: axios to property
 * @Author: ls
 * @Date: 2019-10-17 10:05:03
 * @LastEditTime: 2019-10-17 10:34:17
 * @LastEditors: Please set LastEditors
 */


import axios from 'axios'
import {
    Loading,
    Message
} from 'element-ui'



var loading  //加载变量
function startLoading() {
    loading = Loading.service({
        lock: true,
        text: '拼命加载中~',
        background: 'rgba(0,0,0,0.7)'
    })
}

function endLoading(){
    loading.close()
}


// axios全局默认环境
const ls_default = axios.create({
    baseUrl:'http://api.example.com',
    headers:{
        common:{
            Authorization:'验证authorization'
        },
        post:{
            'Content-Type':'application/x-www-form-urlencoded'
        }
    }
})




// 请求拦截
axios.interceptors.request.use(config=>{
    startLoading()
    return config
},err=>{
    return Promise.reject(err)
})


// 响应拦截
axios.interceptors.response.use(res=>{
    endLoading()
    res
},err=>{
    return Promise.reject(err)
})

// 暴露axios
export default axios